package com.wzy.oa_sys.controller.log;

import com.wzy.oa_sys.model.request.log.LogReq;
import com.wzy.oa_sys.model.response.log.LogResp;
import com.wzy.oa_sys.service.log.LogService;
import com.wzy.oa_sys.util.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/log")
public class LogController {
    @Autowired
    private LogService logService;
    @Autowired
    private JwtUtil jwtUtil;

    @PostMapping("/addLog")
    public void addLog(@RequestBody LogReq logReq, HttpServletRequest request) {
        System.out.println("addLog"+logReq.toString());
        Long userId = null;
        if(logReq.getUserId()==null){
            userId = jwtUtil.extractUserId(request);
        }else{
            userId = logReq.getUserId();
        }
        logService.addLog(logReq,userId);
    }
    @GetMapping("/getLogList")
    public List<LogResp> getLogList(HttpServletRequest request) {
        return logService.getLogList(request);
    }
}
